package com.leesche.zcsp.node.utils;

import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

/**
 * StrKit.
 */
public class StrKit {
	
	/**
	 * 闅忔満16浣嶆暟
	 */
	public static String CreateNoncestr() {
		return CreateNoncestr(16);
	}
	
	/**
	 * 闅忔満鏁�
	 */
	public static String CreateNoncestr(int length) {
		String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		return CreateNoncestr(chars, length);
	}
	
	/**
	 * 闅忔満鏁板瓧
	 */
	public static String CreateNum(int length) {
		String chars = "0123456789";
		return CreateNoncestr(chars, length);
	}
	
	/**
	 * 闅忔満鏁�
	 */
	public static String CreateNoncestr(String chars, int length) {
		String res = "";
		for (int i = 0; i < length; i++) {
			Random rd = new Random();
			res += chars.charAt(rd.nextInt(chars.length() - 1));
		}
		return res;
	}
	/**
	 * 棣栧瓧姣嶅彉灏忓啓
	 */
	public static String firstCharToLowerCase(String str) {
		char firstChar = str.charAt(0);
		if (firstChar >= 'A' && firstChar <= 'Z') {
			char[] arr = str.toCharArray();
			arr[0] += ('a' - 'A');
			return new String(arr);
		}
		return str;
	}
	
	/**
	 * 棣栧瓧姣嶅彉澶у啓
	 */
	public static String firstCharToUpperCase(String str) {
		char firstChar = str.charAt(0);
		if (firstChar >= 'a' && firstChar <= 'z') {
			char[] arr = str.toCharArray();
			arr[0] -= ('a' - 'A');
			return new String(arr);
		}
		return str;
	}
	
	/**
	 * 瀛楃涓蹭负 null 鎴栬�涓� "" 鏃惰繑鍥�true
	 */
	public static boolean isBlank(String str) {
		return str == null || "".equals(str.trim()) ? true : false;
	}
	
	/**
	 * 瀛楃涓蹭笉涓�null 鑰屼笖涓嶄负  "" 鏃惰繑鍥�true
	 */
	public static boolean notBlank(String str) {
		return str == null || "".equals(str.trim()) ? false : true;
	}
	
	public static boolean notBlank(String[] strings) {
		if (strings == null)
			return false;
		for (String str : strings)
			if (str == null || "".equals(str.trim()))
				return false;
		return true;
	}
	
	public static boolean notNull(Object str) {
		return str == null ? false : true;
	}
	
	public static boolean notNull(Object[] paras) {
		if (paras == null)
			return false;
		for (Object obj : paras)
			if (obj == null)
				return false;
		return true;
	}
	

	public static String replaceValue(String value, Map<String, String> map){
		if(StrKit.isBlank(value)){
			return null;
		}
		for(Entry<String,String> entry :map.entrySet()){
			value = value.replace(entry.getKey(), entry.getValue());
		}
		return value;
	}
}